package com.example2.demo;

import ch.qos.logback.classic.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Component
public class CustomCommandLineRunner implements CommandLineRunner {
    public static final Logger logger = (Logger) LoggerFactory.getLogger(Lab2AutoConfig.NoticeListener.class);
    Environment env;

    //使用构造方法注入env
    public CustomCommandLineRunner(Environment env) {
        this.env = env;
    }

    @Override
    public void run(String... args) throws Exception {
        //System.out.println("The CommandLineRunner of SpringBoot autoconfig!");
        logger.info("The CommandLineRunner of SpringBoot autoconfig!");
        //利用random的RadomValuePropertySouce生成一个32位的随机字串
        System.out.println("produce random string:".concat(Objects.requireNonNull(env.getProperty("random."))));
        logger.info("CommandLineRunner!!!!!!!");
    }
}
